<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/css/tipswindown.css"/>
<script type="text/javascript" src="${ctx}/js/tipswindown.js"></script>

<table class="full">
    <tbody>
    <tr>
        <td style="width: 100px">考核</td>
        <td style="width: 50%"><div id="progress1" class="progress">
            <span style="width: ${examProgress}%;"><b>${examProgress}%</b></span>
        </div></td>
        <td style="width: 100px" class="ar">${examCount}/${employeeCount}</td>
        <td style="width: 400px" class="ar"><a
                href="#exam/statisticsview_main.xhtml?p=qual_browse" class="button"><span
                class="icon" style="background:url(${ctx}/images/img/error.png)">&nbsp;</span>查看</a></td>
    </tr>
    <tr>
        <td>ERP计件数据</td>
        <td><div class="progress">
            <span style="width: ${erpLog == null ? 0 : erpLog.progressStr}%;"><b>${erpLog == null ? 0 : erpLog.progressStr}%</b></span>
        </div></td>
        <td class="ar">${erpLog.successCount}/${erpLog.total}</td>
        <td class="ar">
            <s:if test="#request.erpLog == null">
                <a href="javascript:void(0)" id="erp_import_btn" class="button"> <span class="icon" style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a>
            </s:if>
            <s:else>
                <s:if test="#request.erpLog.progress < 100">
                    <a href="javascript:void(0)" id="erp_import_btn" class="button"> <span class="icon" style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a>
                </s:if>
                <a href="javascript:void(0)" onclick="showDiv('erp-data-list')" class="button"> <span class="icon" style="background:url(${ctx}/images/img/accept.png)">&nbsp;</span>查看</a>
                <a href="javascript:void(0)" onclick="cleanImportData('erp')" class="button"> <span class="icon" style="background:url(${ctx}/images/img/accept.png)">&nbsp;</span>清空</a>
            </s:else>
        </td>
    </tr>
    <tr>
        <td>考勤数据</td>
        <td><div class="progress">
            <span style="width: ${attendaceLog == null ? 0 : attendaceLog.progressStr}%;"><b>${attendaceLog == null ? 0 : attendaceLog.progressStr}%</b></span>
        </div></td>
        <td class="ar">${attendaceLog.successCount}/${attendaceLog.total}</td>
        <td class="ar">
            <s:if test="#request.attendaceLog == null">
                <a href="javascript:void(0)" id="attendance_import_btn" class="button" style="display: none;"> <span class="icon" style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a>
                <a href="javascript:void(0)" class="button" onclick="importAttendance()"> <span class="icon" style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a>
            </s:if>
            <s:else>
                <s:if test="#request.attendaceLog.progress < 100">
                    <a href="javascript:void(0)" id="attendance_import_btn" class="button" style="display: none;"> <span class="icon" style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a>
                    <a href="javascript:void(0)" class="button" onclick="importAttendance()"> <span class="icon" style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a>
                </s:if>
                <a href="javascript:void(0)" onclick="showDiv('attendance-data-list')" class="button"> <span class="icon" style="background:url(${ctx}/images/img/accept.png)">&nbsp;</span>查看</a>
                <a href="javascript:void(0)" onclick="cleanImportData('attendance')" class="button"> <span class="icon" style="background:url(${ctx}/images/img/accept.png)">&nbsp;</span>清除</a>
            </s:else>
        </td>
    </tr>
    </tbody>
</table>

<script type="text/javascript">
    $(function(){
        var year = $("#search_year_1").val();
        var month = $("#search_month_1").val();
        //alert("year="+year+",month="+month)
        var url_attendace = '${ctx}/ajax/attendance-data-import.xhtml?organizationId=${organizationId}&year='+year+"&month="+month;
        var url_erp = '${ctx}/ajax/attendance-erp-data-import.xhtml?organizationId=${organizationId}&year='+year+"&month="+month;
        if($("#attendance_import_btn").length > 0){
            AjaxUpload.init(url_attendace, "attendance_import_btn", "", "");
        }
        if($("#erp_import_btn").length > 0){
            AjaxUpload.init(url_erp, "erp_import_btn", "", "");
        }
        $("#total_progress").html("${totalProgressStr}%");
    });


    function importAttendance(){
        var year = $("#search_year_1").val();
        var month = $("#search_month_1").val();
        var url = '${ctx}/ajax/attendance-data-import2.xhtml?organizationId=${organizationId}&year='+year+"&month="+month;
        $.ajax(url, {
            type : "post",
            dataType : "json",
            success : function(messaeg) {
                if(messaeg == "success"){
                    alert("导入成功");
                    doSearch();
                    return;
                }
                if(messaeg != null && messaeg.length > 0){
                    alert("导入失败");
                }else{
                    alert("导入成功");
                    //location.reload();
                    doSearch();
                }
            }
        });
    }

    function showDiv(actionUrl){
        var year = $("#search_year_1").val();
        var month = $("#search_month_1").val();
        //url = /salary/attendance-data-list.xhtml 或 /salary/erp-data-list.xhtml
        tipsWindown("标题","url:post?${ctx}/salary/"+actionUrl+".xhtml?organizationId=${organizationId}&year="+year+"&month="+month,"800","400","true","","true","text");
    }

    function cleanImportData(type){
        if(!confirm("确定要清除数据吗？")){
            return;
        }
        $.ajax('${ctx}/ajax/attendance-data-remove.xhtml', {
            type : "get",
            dataType : "json",
            data:{"type": type, "organizationId":"${organizationId}", "year":"${year}", "month":"${month}"},
            success : function(result) {
                if(result != null && result == true){
                    alert("清除成功");
                    doSearch();
                }else{
                    alert("清除失败");
                }
            }
        });
    }
</script>
